home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 483 / mkrscsrc / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-26  |  6.2 KB  |  297 lines

  1. #include "stdio.h"
  2. #include "gemdefs.h"
  3. #include "obdefs.h"
  4. #include "osbind.h"
  5. #include "mkrsc.h"
  6. #include "globals.h"
  7.  
  8.  
  9. int init()
  10. {
  11.     if (!rsrc_load("mkrsc.rsc")) {
  12.         form_alert(1, "[0][Cannot find mkrcs.rsc file|Terminating ...][OK]");
  13.         exit(1);
  14.     }
  15.  /* set addresses for dialog boxes and menubar */
  16.        rsrc_gaddr(0, MKRSCMNU, &mkrscmnu);
  17.     rsrc_gaddr(0, BUTTONT, &buttont);
  18.     rsrc_gaddr(0, OLDTREE, &oldtree);
  19.     rsrc_gaddr(0, TIST, &tist);
  20.     rsrc_gaddr(0, BOXCT, &boxct);
  21.     rsrc_gaddr(0, TREICONT, &treicont);
  22.     rsrc_gaddr(0, OBICONT, &obicont);
  23.     rsrc_gaddr(0, MNUICONT, &mnuicont);
  24.     rsrc_gaddr(0, NAMOBJT, &namobjt);
  25.     rsrc_gaddr(0, DUMMNU, &dummnu);
  26.     rsrc_gaddr(0, MTBOX1, &mtbox1);
  27.     rsrc_gaddr(0, NEWTREE, &newtree);
  28.     rsrc_gaddr(0, BOXT, &boxt);
  29.     rsrc_gaddr(0, ABOUTT, &aboutt);
  30.     rsrc_gaddr(0, SORTD, &sortd);
  31.     rsrc_gaddr(0, NEWTOP, &newtop);
  32.  
  33.     mkrscmnu[SNAP].ob_state = CHECKED;
  34.     snap = TRUE;
  35.  
  36. }
  37.  
  38.  
  39. /*
  40.     open_workstation  -  Open a VDI virtual workstation.
  41.     from Laser C VDI examples. Also sets up the MFDB
  42.  
  43.     Note:
  44.       information about the workstation is returned in the
  45.       parameter `form'. appl_init() must be called previously.
  46. */
  47. int open_workstation(form)
  48.     register MFDB   *form;
  49. {
  50.     register int x;
  51.     int      work_in[11];
  52.     int      work_out[57];
  53.     int      dummy;
  54.     int      whandle;
  55.     int         ret;
  56. #ifdef __GNUC__
  57.     short    GDOS = 0;
  58. #else
  59.     int      GDOS = 0;
  60. #endif
  61.   
  62.       /*
  63.           Does GDOS exist?
  64.       */
  65. #ifndef __GNUC__
  66.       asm {
  67.             move.w  #-2, D0
  68.             trap    #2
  69.             cmp.w   #-2, D0
  70.             beq     gdos_not_installed
  71.             move.w  #1, GDOS(A6)
  72.     gdos_not_installed:
  73.       }
  74. #else
  75.     __asm__ volatile
  76.     ("
  77.             movew  #-2, d0
  78.             trap   #2
  79.             cmpw   #-2, d0
  80.             beq    1f
  81.             movew  #1, %0
  82.          1:"
  83.     : "=g"(GDOS)    /* outputs */
  84.     :
  85.     : "d0", "d1", "d2", "a0", "a1", "a2"); /* clobbered reggies */
  86. #endif
  87.  
  88.     /*
  89.         Initialize workstation variables.
  90.     */
  91.     if (GDOS)
  92.         work_in[0] = Getrez() + 2;
  93.     else
  94.         work_in[0] = 1;
  95.  
  96.     for(x=1; x<10; x++)
  97.         work_in[x] = 1;
  98.  
  99.     /*
  100.         Set for Raster Coordinate System.
  101.     */
  102.     work_in[10] = 2;
  103.  
  104.     /*
  105.         Get the workstaion handle and the character sizes
  106.         Get the desktop dimensions
  107.         Open Virtual Workstation
  108.     */
  109.         whandle = graf_handle(&gl_wchar,&gl_hchar,&gl_wbox,&gl_hbox);
  110.          ret = wind_get(0, WF_WORKXYWH, &xdesk, &ydesk, &wdesk, &hdesk);
  111.         v_opnvwk(work_in, &whandle, work_out);
  112.  
  113.     /*  
  114.         Check for error.
  115.     */
  116.     if (!whandle) {
  117.         Cconws("\033E Error: Cannot open Virtual Device");
  118.         Bconin(2);
  119.         exit(1);
  120.     }
  121.  
  122.     /*
  123.         Set up the Memory Form Definition Block (MFDB).  This 
  124.         structure is defined in <gemdefs.h>.
  125.     */
  126.  
  127.     /*
  128.         The Base address of the drawing screen.
  129.     */
  130.     form -> fd_addr = Logbase();
  131.  
  132.     /*
  133.         The width of the screen in pixels.
  134.     */
  135.     form -> fd_w    = work_out[0] + 1;
  136.  
  137.     /*
  138.         The height of the screen in pixels.
  139.     */
  140.     form -> fd_h    = work_out[1] + 1;
  141.  
  142.     /*
  143.         The number of words in the width of the screen.
  144.     */
  145.     form -> fd_wdwidth  = form -> fd_w / 16;
  146.  
  147.     /*
  148.         Working in a raster coordinate system.  
  149.     */
  150.     form -> fd_stand       = 0;
  151.  
  152.     /*
  153.         The number of drawing planes.
  154.     */
  155.     switch(work_out[13]) {
  156.         case 16: form -> fd_nplanes = 4; break;
  157.         case 8: form -> fd_nplanes = 3; break;
  158.         case 4: form -> fd_nplanes = 2; break;
  159.         default: form -> fd_nplanes = 1; break;
  160.     }  
  161.  
  162.     /*
  163.         Return the workstation whandle.
  164.     */
  165.     return whandle;
  166. }
  167.  
  168.  
  169. /*
  170.     shutdown - is the code that closes down the application.  This routine
  171.         is called when errors occurs and guarantees that all window's will
  172.         be closed properly before exiting.
  173. */
  174. shutdown(code)
  175.     int code;
  176. {
  177.     /*
  178.         Clean up memory.
  179.     */
  180.     cleanup();
  181.  
  182.     /*
  183.         Clean up the io buffer because of bug in TOS ?
  184.     */
  185.  
  186.     while(Cconis()) Crawcin();
  187.  
  188.     /*
  189.         Close the workstation and shut down the application.
  190.     */
  191.  
  192.     v_clsvwk(handle);
  193.  
  194.     appl_exit();
  195.  
  196.     /*
  197.         bye ...
  198.     */
  199.     exit(code);
  200. }
  201.  
  202.  
  203. /*
  204.     cleanup - releases the memory used by the application.
  205. */
  206. cleanup()
  207. {
  208.     windowptr    thewin;
  209.  
  210.     /*
  211.         Close down the windows.
  212.     */
  213.     if(firstwindow)
  214.     for (thewin = firstwindow; thewin; thewin = thewin -> next)
  215.         dispose_window(thewin);
  216.  
  217. /*        Free memory used by resource.    */
  218.     
  219.     rsrc_free(); 
  220.  
  221. }
  222.  
  223. init_path()    /* initialize fs_inpath with current path */
  224. {
  225.     int drv;
  226.     char lastpath[80];
  227.  
  228.     drv = Dgetdrv();
  229.     Dgetpath(lastpath,drv+1);
  230.     sprintf(fs_inpath,"%c:%s\\*.*",'A' + drv,lastpath);
  231.     strcpy(fs_insel,"untitled");
  232. }
  233.  
  234. int    create_newtops()
  235. {
  236.     int numobjs, order[25], i, j;
  237.  
  238.     j = 1;
  239.     tredesk[0] = *newtop;
  240.     tredesk[0].ob_x = xdesk;
  241.     tredesk[0].ob_y = ydesk;
  242.     tredesk[0].ob_width = wdesk;
  243.     tredesk[0].ob_height = hdesk;
  244.  
  245.     numobjs = trav_tree(treicont,order);
  246.     for(i=1;i<numobjs;i++)
  247.         tredesk[j++] = treicont[order[i]];
  248.  
  249.     tredesk[0].ob_flags = 0;
  250.     tredesk[j-1].ob_flags = 0x20;
  251.     objc_add(tredesk,0,1);
  252.  
  253.  
  254.     j = 1;
  255.     mnudesk[0] = *newtop;
  256.     mnudesk[0].ob_x = xdesk;
  257.     mnudesk[0].ob_y = ydesk;
  258.     mnudesk[0].ob_width = wdesk;
  259.     mnudesk[0].ob_height = hdesk;
  260.  
  261.     numobjs = trav_tree(mnuicont,order);
  262.     for(i=1;i<numobjs;i++)
  263.         mnudesk[j++] = mnuicont[order[i]];
  264.     mnudesk[0].ob_flags = 0;
  265.     mnudesk[j-1].ob_flags = 0x20;
  266.     objc_add(mnudesk,0,1);
  267.  
  268.     j = 1;
  269.     obdesk[0] = *newtop;
  270.     obdesk[0].ob_x = xdesk;
  271.     obdesk[0].ob_y = ydesk;
  272.     obdesk[0].ob_width = wdesk;
  273.     obdesk[0].ob_height = hdesk;
  274.  
  275.     numobjs = trav_tree(obicont,order);
  276.     for(i=1;i<numobjs;i++)
  277.         obdesk[j++] = obicont[order[i]];
  278.     obdesk[0].ob_flags = 0;
  279.     obdesk[j-1].ob_flags = 0x20;
  280.     objc_add(obdesk,0,1);
  281.  
  282.     hightreadr = (int)(((long)tredesk) >>16);
  283.     lowtreadr = (int)tredesk;
  284.     highmnuadr = (int)(((long)mnudesk) >>16);
  285.     lowmnuadr = (int)mnudesk;
  286.     highobadr = (int)(((long)obdesk) >>16);
  287.     lowobadr = (int)obdesk;
  288.  
  289.     treicont[1].ob_x = xdesk;
  290.     treicont[1].ob_y = ydesk;
  291.     mnuicont[1].ob_x = xdesk;
  292.     mnuicont[1].ob_y = ydesk;
  293.     obicont[1].ob_x = xdesk;
  294.     obicont[1].ob_y = ydesk;
  295. }
  296.     
  297.